// utils/Component/subject/ChoiceQuestion/ChoiceQuestion.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    rubric: "",
    daan: '请选择答案',
    checked: false,
    remarktype: "",//题目类型
    tfbloon: "",//判断选择题是否可以选择
    Choicemydaan: ""
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //选择题的数据中心
    tiantimu(xiaoti, remarktype) {
      let tfbloon = "";//判断选择题是否可以选择
    // remarktype的解释
    // 0 == 可以修改选择的
    // 1 == 可以增加、修改评语，得分
    // 2 == 不可以修改卷子
    // 3 == 不可以修改卷子而且有评语和得分
    // 4 == 不可以修改卷子,可以看到答案
      if (remarktype == 1 || remarktype == 2 || remarktype == 3 || remarktype == 4) {
        tfbloon = true;//判断选择题可以修改
      } else {
        tfbloon = false;//判断选择题不可以修改
      }
      this.setData({
        rubric: xiaoti,//小题
        daan: '请选择答案',//答案
        checked: false,//？？
        remarktype: remarktype,//题目的类型
        tfbloon: tfbloon//判断选择题可以修改
      })
      console.log(this.data.rubric);
      if (this.data.rubric.typecode == "多选题" || this.data.rubric.typecode_dictionary_title == "多选题") {
        if (this.data.rubric.answer.indexOf(',') >= 0) {
          this.data.rubric.answer = this.data.rubric.answer.split(',');
          this.setData({
            rubric: this.data.rubric,
          })
          console.log(this.data.rubric);

        } else {

        }
      } else {

      }

      if (remarktype == 4) {
        let dxanswer = "";
        let Choicemydaan = "";
        if (this.data.rubric.typecode == "多选题" || this.data.rubric.typecode_dictionary_title == "多选题") {
          // if (this.data.rubric.typecode == "综合题"){
          //   this.data.rubric.answer = 
          // }
          dxanswer = this.duoxuan(this.data.rubric.answer);
          Choicemydaan = this.trimSpace(dxanswer);
          this.setData({
            daan: this.duoxuan(this.data.rubric.answer),
            Choicemydaan: Choicemydaan
          })
        } else {
          dxanswer = this.data.rubric.answer
          Choicemydaan = dxanswer;
          this.setData({
            daan: this.data.rubric.answer,
            Choicemydaan: Choicemydaan
          })
        }
      }
      // console.log("选择",this.data.daan);

      // console.log(this.data.rubric);

    },
    //判断单选题的方法,可以获得单选的答案
    listenerRadioGroup: function (e) {
      console.log(e);
      this.setData({
        daan: e.detail.value,
      });
    },
    //判断多选题的方法,可以获得单选的答案
    checkboxgroupBindchange: function (e) {
      var temp1 = e.detail.value.sort();
      console.log(temp1)
      let Choicemydaan = this.trimSpace(temp1);
      temp1 = this.duoxuan(temp1);
      if (temp1.length != 0) {
        this.setData({
          daan: temp1,
          Choicemydaan: Choicemydaan,

        })
      } else {
        this.setData({
          daan: '请选择答案',
        })
      }
    },
    mydaan() {
      console.log(this.data.daan);
      if (this.data.rubric.typecode == "多选题" || this.data.rubric.typecode_dictionary_title == "多选题") {
        return this.data.Choicemydaan;
      } else {
        return this.data.daan
      }


    },
    zxtext(nextext) {
      console.log(nextext);
      this.setData({
        Choicemydaan: nextext,
      })
      var nextextsp = [];
      if (nextext.indexOf(',') >= 0) {
        nextextsp = nextext.split(',');
      } else {
        nextextsp = nextext;
      }
      console.log(nextextsp);
      if (this.data.rubric.typecode == '多选题' || this.data.rubric.typecode_dictionary_title == '多选题') {
        nextextsp = this.duoxuan(nextextsp);
        this.setData({
          daan: nextextsp,
        })
      } else {
        this.setData({
          daan: nextextsp,
        })
      }
      let newa = nextextsp;
      let Choicemydaan = this.trimSpace(newa);
      this.setData({
        Choicemydaan: Choicemydaan
      })
      console.log(this.data.daan);
    },
    // 多选题题
    duoxuan: function (nextextsp) {
      var shuzu = [];

      for (let a = 0; a < nextextsp.length; a++) {

        if (nextextsp[a] == "A") {
          shuzu[0] = "A";
        } else {
          shuzu[0] == "A" ? shuzu[0] = "A" : shuzu[0] = "";
        }

        if (nextextsp[a] == "B") {
          shuzu[1] = "B";
        } else {
          shuzu[1] == "B" ? shuzu[1] = "B" : shuzu[1] = "";
        }

        if (nextextsp[a] == "C") {
          shuzu[2] = "C";
        }
        else {
          shuzu[2] == "C" ? shuzu[2] = "C" : shuzu[2] = "";
        }

        if (nextextsp[a] == "D") {
          shuzu[3] = "D";
        } else {
          shuzu[3] == "D" ? shuzu[3] = "D" : shuzu[3] = "";
        }

        if (nextextsp[a] == "E") {
          shuzu[4] = "E";
        } else {
          shuzu[4] == "E" ? shuzu[4] = "E" : shuzu[4] = "";

        }

        if (nextextsp[a] == "F") {
          shuzu[5] = "F";
        } else {
          shuzu[5] == "F" ? shuzu[5] = "F" : shuzu[5] = "";
        }

        if (nextextsp[a] == "G") {
          shuzu[6] = "G";
        } else {
          shuzu[6] == "G" ? shuzu[6] = "G" : shuzu[6] = "";
        }

        if (nextextsp[a] == "H") {
          shuzu[7] = "H";
        } else {
          shuzu[7] == "H" ? shuzu[7] = "H" : shuzu[7] = "";
        }

        if (nextextsp[a] == "I") {
          shuzu[8] = "I";
        } else {
          shuzu[8] == "I" ? shuzu[8] = "I" : shuzu[8] = "";
        }

        if (nextextsp[a] == "J") {
          shuzu[9] = "J";
        } else {
          shuzu[9] == "J" ? shuzu[9] = "J" : shuzu[9] = "";
        }

        if (nextextsp[a] == "K") {
          shuzu[10] = "K";
        } else {
          shuzu[10] == "K" ? shuzu[10] = "K" : shuzu[10] = "";
        }
      }
      console.log(shuzu);
      return shuzu;

    },
    trimSpace: function (array) {
      for (var i = 0; i < array.length; i++) {
        if (array[i] == "" || typeof (array[i]) == "undefined") {
          array.splice(i, 1);
          i = i - 1;

        }
      }
      return array;
    }

  }
})
